package cn.edu.sgu.www.mhxysy.service.children.impl;

import cn.edu.sgu.www.mhxysy.dto.children.ChildrenZizhiDTO;
import cn.edu.sgu.www.mhxysy.entity.children.ChildrenZizhi;
import cn.edu.sgu.www.mhxysy.mapper.children.ChildrenZizhiMapper;
import cn.edu.sgu.www.mhxysy.service.children.ChildrenZizhiService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Service
public class ChildrenZizhiServiceImpl implements ChildrenZizhiService {

    private final ChildrenZizhiMapper childrenZizhiMapper;

    @Autowired
    public ChildrenZizhiServiceImpl(ChildrenZizhiMapper childrenZizhiMapper) {
        this.childrenZizhiMapper = childrenZizhiMapper;
    }

    @Override
    public void updateByChildrenId(ChildrenZizhiDTO childrenZizhiDTO) {
        ChildrenZizhi childrenZizhi = new ChildrenZizhi();

        childrenZizhi.setGjzz(childrenZizhiDTO.getGjzz());
        childrenZizhi.setFyzz(childrenZizhiDTO.getFyzz());
        childrenZizhi.setTlzz(childrenZizhiDTO.getTlzz());
        childrenZizhi.setFlzz(childrenZizhiDTO.getFlzz());
        childrenZizhi.setSdzz(childrenZizhiDTO.getSdzz());
        childrenZizhi.setChengzhang(childrenZizhiDTO.getChengzhang());

        UpdateWrapper<ChildrenZizhi> updateWrapper = new UpdateWrapper<>();

        updateWrapper.eq("children_id", childrenZizhiDTO.getChildrenId());

        childrenZizhiMapper.update(childrenZizhi, updateWrapper);
    }

    @Override
    public ChildrenZizhi selectByChildrenId(String childrenId) {
        QueryWrapper<ChildrenZizhi> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("children_id", childrenId);

        return childrenZizhiMapper.selectOne(queryWrapper);
    }

}